<?php
include_once "model.php";

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$id = $_POST["id"];
	$password = $_POST["password"];
	if ($password == ADMIN_PASSWORD) {
		$model->delete_node($id);
	}
	else {		
		header('Location: /fractal-narratives/error.php');
		return;
	}

	header('Location: /fractal-narratives/admin.php');
	
}
elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
	$id = $_GET["id"];

	$node = $model->get_node($id);

	include("inc/header.inc");
	echo 'Really delete node '.$id,' ('.$node['content'].') and all its children?';

	echo '<form action="delete.php" method="post">';
	echo '<input type="hidden" name="id" value="'.$id.'"/>';
	echo '<input type="password" name="password"/>';
	echo '<input type="submit" value="Confirm"/>';
	echo '</form>';

	include("inc/footer.inc");
}
?>
